package xyz.xuminghai.javafx_learn.animation.transition;

import javafx.animation.PauseTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.SequentialTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * 2023/7/22 12:40 星期六<br/>
 * 此Transition在其duration结束时执行Animation.onFinished
 *
 * @author xuMingHai
 */
public class PauseTransitionApp extends Application {

    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {
        Rectangle rectangle = new Rectangle(100.0, 100.0);

        ScaleTransition scaleTransition = new ScaleTransition(Duration.millis(3000.0),
                rectangle);
        // from 起始值 to 最终值 by 起始值加by值
        scaleTransition.setToX(0.5);
        scaleTransition.setToY(0.5);

        new SequentialTransition(
                // 暂停2秒
                new PauseTransition(Duration.millis(2000.0)),
                scaleTransition
        ).play();

        root.setCenter(rectangle);
    }


    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
